<template>
	<view class="newTeam">
		<view class="newTeam_top">
			<view class="top_count">
				<view class="count_nums">
					{{total}}人
				</view>
				<view class="count_title">
					我的团队
				</view>
				<view class="count_desc">
					邀请码： <span @click="copy(userInfo.inviter_code)">{{userInfo.inviter_code}}</span>
				</view>
				<button class="share_button" open-type="share" v-if="false">立即邀请</button>
			</view>
		</view>
		<view class="newTeam_title">
			团队直推
		</view>
		<view class="newTeam_centent">
			<view class="newTeam_one" v-for="(item,index) in tuanduiArray" :key="index">
				<view class="newTeam_one_left">
					<image :src="item.avatar" mode="aspectFill"></image>
					<view class="newTeam_one_leftActive">
						<view class="leftActive_name">
							{{item.nickname}}
						</view>
						<view class="leftActive_time">
							{{item.createtime}}
						</view>
					</view>
				</view>
				<view class="newTeam_one_right" v-if="item.is_vip">
					vip
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				page:1,
				last_page:1,
				total:0,
				tuanduiArray:[],
				userInfo:"",
			}
		},
		onLoad() {
			this.loadData()
			this.getYaoqing('init')
		},
		onPullDownRefresh() {
			setTimeout(()=>{
				uni.stopPullDownRefresh()
			},1500)
			this.getYaoqing('init')
		},
		onReachBottom() {
			if(this.page<this.last_page){
				this.page++
				this.getYaoqing()
			}
		},
		onShareAppMessage(res) {
			if(res.from=='button'){
				
			}
			return {
				title: '', // 默认为小程序名称
				path: '/pages/user/newTeam/newTeam?inviter_code='+this.userInfo.inviter_code, // 默认为当前页面路径
				imageUrl: '' // 默认为当前页面的截图
			}
			console.log(res)
		},
		onShareTimeline(res) {
			console.log(res)
			if(res.from=='button'){
				
			}
			return {
				title: '', // 默认为小程序名称
				path: '/pages/user/newTeam/newTeam?inviter_code='+this.userInfo.inviter_code, // 默认为当前页面路径
				imageUrl: '' // 默认为当前页面的截图
			}
		},
		methods:{
			copy(value){
				uni.setClipboardData({
					data:value,
					success: () => {
						uni.showToast({
							title:"复制成功"
						})
					}
				})
			},
			async loadData() {
				await uni.request({
					url: '/wanlshop/user/refresh',
					method: 'POST',
					success: res => {
						this.userInfo=res.data.userinfo
						// console.log(res.data.userinfo,'89999999999999999999999999999999999')
					}
				});
			},
			async getYaoqing(type){
				if(type=='init'){
					this.page=1
					this.tuanduiArray=[]
				}
				await uni.request({
					url:"/wanlshop/user/yaoqing",
					method:"POST",
					data:{
						page:this.page
					},
					success: (res) => {
						this.total=res.data.total
						this.last_page=res.data.last_page
						if(res.data.data.length){
							if(this.page==1){
								this.tuanduiArray=res.data.data
							}else{
								this.tuanduiArray=[...this.tuanduiArray,...res.data.data]
							}
						}
					}
				})
			}
		}
		
	}
</script>

<style lang="scss" scoped>
	.newTeam{
		width: 100%;
		.newTeam_top{
			width: 100%;
			min-height: 350rpx;
			background-color: #fe6600;
			display: flex;
			align-items: center;
			justify-content: center;
			.top_count{
				text-align: center;
				.count_nums{
					font-size: 60rpx;
					font-weight: 800;
					color: #ffffff;
				}
				.count_title{
					font-size: 30rpx;
					color: #ffffff;
					margin-top: 15rpx;
				}
				.count_desc{
					font-size: 28rpx;
					color: #ffffff;
					margin-top: 25rpx;
					span{
						font-size: 35rpx;
					}
				}
				.share_button{
					width: 400rpx;
					border-radius: 45rpx;
					margin-top: 20rpx;
				}
			}
		}
		.newTeam_title{
			width: 100%;
			box-sizing: border-box;
			padding:  40rpx 30rpx;
			font-size: 30rpx;
			font-weight: 800;
			color: #333333;
		}
		.newTeam_centent{
			width: 100%;
			background-color: #ffffff;
			box-sizing: border-box;
			padding: 0 24rpx;
			.newTeam_one{
				width: 100%;
				height: 120rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid #f7f7f7;
				.newTeam_one_left{
					display: flex;
					align-items: center;
					image{
						width: 100rpx;
						height: 100rpx;
						background-color: #cccccc;
						border-radius: 50%;
						margin-right: 25rpx;
					}
					.newTeam_one_leftActive{
						.leftActive_name{
							font-size: 30rpx;
							font-weight: 800;
							color: #333333;
						}
						.leftActive_time{
							font-size: 24rpx;
							color: #666666;
							margin-top: 20rpx;
						}
					}
				}
				.newTeam_one_right{
					font-size: 40rpx;
					font-weight: 500;
					color: #ff0000;
					margin-left: 15rpx;
				}
			}
		}
	}
</style>